<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('admin', function (Blueprint $table) {
            $table->increments('id');

            // // not null
            // $table->uuid('uuid')->comment('uuid');
            // // not null
            // $table->string('username', 55)->comment('用户名varchar');
            // // not null
            // $table->char('password', 32)->comment('md5加密密码');
            // // not null, tinyint(1), default 1;
            // $table->boolean('gender')->default(true)->comment('性别0女1男');

            // // not null
            // $table->string('title', 255)->comment('标题');
            // // null
            // $table->text('description')->nullable()->comment('描述');
            // // null
            // $table->text('content')->nullable()->comment('内容');


            // 从 create_users_table 迁移文件中复制来的
            $table->string('username')->comment('用户名');
            $table->string('email')->unique()->comment('邮箱');
            $table->string('password')->comment('密码');
            $table->rememberToken()->comment('记住我');

            $table->char('mobile', 11)->comment('手机号码');
            $table->integer('dept_id')->comment('部门id');

            // not null
            $table->enum('so_status', ['0', '1', '2'])->default('0')->comment('状态');
            $table->integer('so_order')->default(0)->comment('排序');
            $table->timestamp('last_login_at')->nullable()->comment('上次登录成功的时间');
            $table->string('last_login_ip', 25)->default('')->comment('上次登录IP');
            $table->timestamp('last_login_error_at')->nullable()->comment('上次登录失败的时间');
            $table->integer('login_times')->default(0)->comment('登录成功的次数');
            $table->integer('login_error_times')->default(0)->comment('登录失败的次数');


            // $table->timestamps(0); 虽然会同时生成 created_at、updated_at 两个字段，但 created_at 没有默认值，不好。


            // not null
            $table->timestamp('created_at', 0)->nullable()->useCurrent()->comment('创建时间');
            // null
            $table->timestamp('updated_at', 0)->nullable()->comment('更新时间');
            // null
            $table->softDeletes('deleted_at', 0)->nullable()->comment('软删除时间');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('admin');
    }
}
